package com.huadao.pda.common;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.huadao.pda.R;

public class ToastUtil {
    private static final ToastUtil ourInstance = new ToastUtil();

    public static ToastUtil getInstance() {
        return ourInstance;
    }

    private ToastUtil() {
    }

    public static void showTextToast(Context context, String message){
        View toastview= LayoutInflater.from(context).inflate(R.layout.item_toast_text,null);
        TextView text = (TextView) toastview.findViewById(R.id.tv_message);
        text.setText(message);
        Toast toast=new Toast(context);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(toastview);
        toast.show();
    }

    public static void showImageTitleTextToast(Context context, int imageRes,String titleText,String message){
        View toastview= LayoutInflater.from(context).inflate(R.layout.item_toast_image_title_text,null);
        TextView title = (TextView) toastview.findViewById(R.id.tv_title);
        TextView text = (TextView) toastview.findViewById(R.id.tv_message);
        ImageView icon = (ImageView) toastview.findViewById(R.id.iv_icon);
        title.setText(titleText);
        text.setText(message);
        icon.setImageResource(imageRes);
        Toast toast=new Toast(context);
        toast.setGravity(Gravity.CENTER,0,0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(toastview);
        toast.show();
    }

}
